<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue2 自定义指令 测试 loading</title>
  <style>
    .table {
      width: 400px;
      height: 400px;
      border: 1px solid red;
    }

    .loading {
      position: relative;
    }

    .loading::before {
      content: '正在加载...';
      position: absolute;
      display: flex;
      justify-content: center;
      align-items: center;
      /* top: 0; */
      /* left: 0; */
      width: 100%;
      height: 100%;

    }
  </style>
</head>

<body>
  <div id="app">
    <div class="table" v-loading="loading"></div>
  </div>
  <script src="js/vue.js"></script>
  <script>
    Vue.directive('loading', {
      bind(el, binding, vnode) {
        console.log('bind');
      },
      inserted(el, binding, vnode) {
        console.log('inserted');
        // el.focus()
        // el.classList.add() 为元素添加指定类名
        el.classList.add('loading')
      },
      update(el, binding, vnode) {
        // el.classList.remove() 移除元素指定类名
        el.classList.remove('loading')
      }
    });
    const app = new Vue({
      el: "#app",
      created() {
        console.log('created:')
        setTimeout(() => {
          this.loading = false
        }, 2000);
      },
      data: {
        loading: true
      }
    })
  </script>
</body>

</html>